import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
static class Station {
  int identifiantStation;
  float longitude;
  float latitude;
  String nom;
  String commune;
  int type;

  static final int METRO = 1;
  static final int TRAM = 2;
  static final int RER = 3;
  static final int BUS = 4;
  
  static float minlon=Float.NaN;
  static float minlat=Float.NaN;
  static float maxlon=Float.NaN;
  static float maxlat=Float.NaN;

  Station(String line) {
    String infos[] = line.split("#");
    identifiantStation = Integer.parseInt(infos[0]);
    longitude = Float.parseFloat(infos[1]);
    latitude = Float.parseFloat(infos[2]);
    nom = infos[3];
    commune = infos[4];
    type = getType(infos[5]);
    minlon = min(minlon, longitude);
    maxlon = max(maxlon, longitude);
    minlat = min(minlat, latitude);
    maxlat = max(maxlat, latitude);
  }

  //Retourne une map Clé : identifiant station, Valeur : station
  static Map<Integer, Station> chargerStations(String lines[]) {
    Map<Integer, Station> stations = new HashMap<Integer, Station>(); 
    for (int i = 0; i < lines.length; i++) {
      Station s = new Station(lines[i]);
      if (stations.get(s.identifiantStation) != null) {
        System.out.println("Station " + s.identifiantStation + " dupliquée");
      }
      stations.put(s.identifiantStation, s);
    }
    return stations;
  }
  
  static Map<String, Entry<Float, Float>> chargerPositions(Map<Integer, Station> stations) {
    Map<String, Entry<Float, Float>> positions = new HashMap<String, Entry<Float, Float>>();
    for (Station s : stations.values()) {
      Entry<Float, Float> e = positions.get(s.nom);
      if(e == null){
        positions.put(s.nom, new SimpleEntry(s.longitude, s.latitude));
      }
    }
    return positions;
  }
  
  
  static int getType(String nom){
    int type = 0;
    nom = nom.toLowerCase();
    if (nom.equals("metro") || nom.equals("métro")) {
      type = METRO;
    }
    else if (nom.equals("tram")) {
      type = TRAM;
    }
    else if (nom.equals("rer")) {
      type = RER;
    }
    else if (nom.equals("bus")) {
      type = BUS;
    }
    else{
      System.err.println("Type " + nom + " inconnu");
      System.exit(1);
    }
    return type;
  }
}
